/***************************************************************************
 *  Filename: computerwidget.h
 *  Class: ComputerWidget
 *
 *  Copyright 2012  Xander van Kooten
 *  <xandervk@gmail.com>
 *
 *  Copyright 2012  Mario Henrique Voorsluys
 *  <forcaeluz@gmail.com>
 *
 ****************************************************************************/

/*
 *
 * This file is part of Parsax-Remote-Controller.
 *
 *    Parsax-Remote-Controller is free software: you can redistribute it
 *    and/or modify it under the terms of the GNU General Public License
 *    as published by the Free Software Foundation, either version 3 of the
 *    License, or (at your option) any later version.
 *
 *    Parsax-Remote-Controller is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with Parsax-Remote-Controller.
 *    If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef COMPUTERWIDGET_H
#define COMPUTERWIDGET_H

#include <QWidget>
#include "mastercommunicator.h"
#include "processgui.h"
#include "processmodel.h"
#include "messageparser.h"
#include "remotecomputer.h"
#include "remoteprocess.h"

namespace Ui {
class ComputerWidget;
}

class ComputerWidget : public QWidget
{
    Q_OBJECT
    
public:
    explicit ComputerWidget(RemoteComputer *comp = 0, QWidget *parent = 0);
    ~ComputerWidget();

    void initialize();
    void setName(QString tname);
    void setAddress(QString taddress);
    void setPort(int tport);

    QString getName();
    QString getAddress();
    int getPort();

    void addProccess();
    void addProccess(QString id, QString program, QStringList parameters, int timeout);
    void addProccess(ProcessGUI *newProc);

    void closeConnection();
    QList<ProcessGUI*> getProcess();

    RemoteComputer* getComputer();
signals:
    void processAdded(ProcessGUI *prcs);
    void processRemoved(ProcessGUI *prcs);
    void nameChanged(ComputerWidget *pc, QString newName);
private:
    Ui::ComputerWidget *ui;
    RemoteComputer *computer;
    QString name;
    QString address;
    int port;
    bool connected;
    MasterCommunicator communicationHandler;
    MessageParser parser;
    QMap<QString, ProcessGUI*> processes;
    ProcessModel *model;


private slots:
    void whenDisconnected();
    void whenConnected();
    void whenStatusUpdateReceived(QString id, QString status);
    void whenCLOReceived(QString id, int type, QString message);
    void on_connectButton_clicked();
    void on_startPrcsButton_clicked();
    void on_stopPrcsButton_clicked();
//    void on_tableView_clicked(const QModelIndex &index);
    void on_newPrcsButton_clicked();
    void on_nameEdit_textChanged(const QString &arg1);
    void on_removeButton_clicked();
    void updateButtonStates();
    void on_addressEdit_textChanged(const QString &arg1);
    void on_tableView_customContextMenuRequested(const QPoint &pos);
};

#endif // COMPUTERWIDGET_H
